package ab.mes.controller;

import ab.mes.entity.Bin;
import ab.mes.entity.FinishedProductBin;
import ab.mes.service.FinishedProductBinService;
import ab.mes.service.impl.BinServiceImpl;
import ab.mes.service.impl.FinishedProductBinServiceImpl;
import ab.mes.tools.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/finishedProductBin")
public class FinishedProductBinController {
    @Autowired
    private FinishedProductBinServiceImpl finishedProductBinService;

    //查询物料库位信息
    @PostMapping("/getFinishedProductBin")
    public Result getBin(){
        Result result=new Result();
        try {
            result = finishedProductBinService.getFinishedProductBin();
        }catch (Exception e){
            result.setErrorMessage("查询物料库位失败！");
            e.printStackTrace();
        }
        return result;
    }

    //查询库位编号物料库位信息
    @PostMapping("/getFinishedProductBinById")
    public Result getBinById(String Id){
        Result result=new Result();
        try {
            result = finishedProductBinService.getFinishedProductBinById(Id);
        }catch (Exception e){
            result.setErrorMessage("查询库位失败！");
            e.printStackTrace();
        }
        return result;
    }

    //停启用库位
    @PostMapping("/updateById3")
    public Result updateById(String Id){
        Result result=new Result();
        try {
            finishedProductBinService.updateStateById(Id);
        }catch (Exception e){
            result.setErrorMessage("更新库位状态失败！");
            e.printStackTrace();
        }
        return result;
    }

    //编辑库位
    @PostMapping("/updateById4")
    public Result updateById3(@RequestBody FinishedProductBin finishedProductBin){
        Result result=new Result();
        try {
            finishedProductBinService.editFinishedProductBin(finishedProductBin);
        }catch (Exception e){
            result.setErrorMessage("编辑失败！");
            e.printStackTrace();
        }
        return result;
    }

    //新增库位
    @PostMapping("/insertFinishedProductBin")
    public Result insertFinishedProductBin(@RequestBody FinishedProductBin finishedProductBin){
        Result result=new Result();
        try {
            finishedProductBinService.insertFinishedProductBin(finishedProductBin);
        }catch (Exception e){
            result.setErrorMessage("新增失败！");
            e.printStackTrace();
        }
        return result;
    }
}
